﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using usedcartrade.Models;
using usedcartrade.DataAccessLayer;

namespace usedcartrade.Repositories
{
    public class CarRepository : ICarRepository
    {
        protected UsedCarERPDAL db = new UsedCarERPDAL();

        public void Add(Car car)
        {
            db.cars.Add(car);
        }

        public bool Delete(int id)
        {
            var delcar = db.cars.FirstOrDefault(c => c.ID == id);
            if(delcar!=null)
            {
                db.cars.Remove(delcar);
                db.SaveChanges();
                return true;
            }else
            {
                return false;
            }
        }

        public IQueryable<Car> SelectAll()
        {
            return db.cars;
        }

        public Car SelectByName(string carname)
        {
            return db.cars.FirstOrDefault(c => c.CarName == carname);
        }
    }
}